## to include the current developing tkMD into tcl package search path. Wouldn't be needed for deploy.
set auto_path [concat [pwd]/../../pkg/tkMD $auto_path ]
## start of the program
package require tkMD 1.1
namespace import Data::*

proc getStat { fname } {
    read_data $fname Data
    set title [read_title $fname ]
#    array set filtered [filter Data { @I > [max $Data(I)]/2 }]
    # ave $filtered(I), std $filterd(I)
    stat Data ave std
    set result {}
    foreach col $title {
        lappend result ave($col)
        lappend result $ave($col)
        lappend result std($col)
        lappend result $std($col)
    }
    return $result
}
## Combine all data under same sub-folder into a big table first.
batch_combine [pwd]/run1 eql.dat eql.en eql.sum
batch_combine [pwd]/run1 eql.sum eql.vol eql.sum

## Collect the statistics(average, standard deviation) using the procedure getStat
set result [collect [pwd]/run1 eql.sum run1/@pept/type_@type/run getStat ]
## Output the result in a table.
puts [toTable $result]

